package cn.shyouchi.wuguanjia.android.ui.event.proprietor;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.impl.ModuleItemClickListener;
import cn.shyouchi.wuguanjia.android.widget.GlideCircleTransform;

/**
 * Created by Eenie on 2016/10/25 at 16:51
 * Email: 472279981@qq.com
 * Des:
 */

public class ProprietorInfoAdapter extends BaseQuickAdapter<ProprietorInfoModel,BaseViewHolder> {

    ModuleItemClickListener mListener;
    private boolean isPreview = false;


    public ProprietorInfoAdapter(List<ProprietorInfoModel> data, ModuleItemClickListener listener) {
        super(R.layout.item_proprietor_info_model, data);
        this.mListener = listener;
    }
    public ProprietorInfoAdapter(List<ProprietorInfoModel> data) {
        super(R.layout.item_proprietor_info_model, data);
        isPreview = true;
    }

    @Override
    protected void convert(BaseViewHolder holder, final ProprietorInfoModel entity) {
        ImageView imgHeader = holder.getView(R.id.img_header);
        if (entity.getType() == ProprietorInfoModel.INFO_TYPE_AVATAR) {
            holder.setText(R.id.model_name, entity.getName())
                    .setText(R.id.tv_holder_name, "");
            imgHeader.setVisibility(View.VISIBLE);
            bindImg(mContext, entity.getValue(), imgHeader);
        } else {
            imgHeader.setVisibility(View.GONE);
            holder.setText(R.id.model_name, entity.getName())
                    .setText(R.id.tv_holder_name, TextUtils.isEmpty(entity.getValue()) ? "去设置" : entity.getHintValue());
        }
        if (isPreview) {
            holder.getView(R.id.person_info_next).setVisibility(View.INVISIBLE);
        } else {
            holder.getView(R.id.person_info_next).setVisibility(View.VISIBLE);
        }
        holder.setTextColor(R.id.tv_holder_name, entity.getTxtColor());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.moduleItemClick(entity);
                }
            }
        });
    }

    public void bindImg(Context context, String path, ImageView iv) {
        Glide.with(context)
                .load(path)
                .placeholder(R.mipmap.ic_default_header)
                .transform(new GlideCircleTransform(context))
                .into(iv);
    }
}